package com.ms.jsf.omnifaces;

/**
 * Collection of callback interfaces. Useful in (mini) visitor and strategy patterns.
 *
 * @author Bauke Scholtz
 */
public final class Callback {

    // Constructors ---------------------------------------------------------------------------------------------------

    private Callback() {
        // Hide constructor.
    }

    // Interfaces -----------------------------------------------------------------------------------------------------

    /**
     * Use this if you need a void callback.
     *
     * @author Bauke Scholtz
     */
    public interface Void {

        /**
         * This method should be invoked by the method where you're passing this callback instance to.
         */
        void invoke();

    }

    /**
     * Use this if you need a callback which returns a value.
     *
     * @param <R> The return type.
     * @author Bauke Scholtz
     */
    public interface Returning<R> {

        /**
         * This method should be invoked by the method where you're passing this callback instance to.
         *
         * @return The callback result.
         */
        R invoke();

    }

    /**
     * Use this if you need a callback which takes an argument.
     *
     * @param <A> The argument type.
     * @author Bauke Scholtz
     */
    public interface WithArgument<A> {

        /**
         * This method should be invoked by the method where you're passing this callback instance to.
         *
         * @param a The callback argument to work with.
         */
        void invoke(A a);

    }

    /**
     * Use this if you need a callback which takes an argument and returns a value.
     *
     * @param <R> The return type.
     * @param <A> The argument type.
     * @author Bauke Scholtz
     */
    public interface ReturningWithArgument<R, A> {

        /**
         * This method should be invoked by the method where you're passing this callback instance to.
         *
         * @param a The callback argument to work with.
         * @return The callback result.
         */
        R invoke(A a);

    }

}
